<template>
	<view>
		<s-pull-scroll ref="pullScroll" :pullDown="pullDown" :pullUp="loadData" :back-top="true">
			<view class="content">
				<view class="list">
					<view 
					@click="handleCheck(index)"
					class="item items-center justify-between" 
					v-for="(item,index) in dataList" :key="item.id">
						<view class="left">
							<image v-if="item.check" class="image-block" src="../../static/img/xz.png" mode=""></image>
							<image v-else class="image-block" src="../../static/img/wxz.png" mode=""></image>
						</view>
						<view class="right items-center justify-between">
							<view>
								<view class="name">
									{{item.name}}
								</view>
								<view class="time">
									{{item.createDate}}
								</view>
							</view>
							<view class="price">
								<text style="font-size: 26rpx;">￥</text>
								<text>{{item.payPrice}}</text>
							</view>
						</view>
					</view>
				</view>
			</view>
		</s-pull-scroll>
		<view class="foot items-center justify-between">
			<view class="left items-center" @click="handleAll">
				<view class="icon">
					<image v-if="isAll" class="image-block" src="../../static/img/xz.png" mode=""></image>
					<image v-else class="image-block" src="../../static/img/wxz.png" mode=""></image>
				</view>
				<view class="text">
					全选
				</view>
			</view>
			<view class="right" @click="handleNew">
				下一步
			</view>
		</view>
		<mix-loading v-if="isLoading"></mix-loading>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				dataList:[],
				isAll:false
			};
		},
		onLoad() {
			this.refresh();
		},
		methods:{
			pullDown(pullScroll) {
				setTimeout(() => {
					this.loadData(pullScroll);
				}, 200);
			},
			handleAll(){
				this.dataList.forEach(el=>{
					el.check = !this.isAll
				})
				this.isAll = !this.isAll
			},
			handleCheck(index){
				this.$set(this.dataList[index],'check',!this.dataList[index].check)
			},
			handleNew(){
				var arr = this.dataList.filter(el=>el.check)
				if(arr.length < 1) return this.$util.msg('至少选择一条内容')
				getApp().globalData.invoiceCheck = arr
				this.navTo('./invoice?type=2')
			},
			async loadData(pullScroll) {
				const data = {
					uid: uni.getStorageSync('uid'),
					pageNo: pullScroll.page,
					pageSize: '10'
				};
				if (pullScroll.page == 1) this.dataList = [];
				const res = await this.$request('user/can-invoice', data, { showLoading: true });
				if (res.result == 0) {
					res.data.list.forEach(el=>{
						this.$set(el,'check',false)
					})
					this.dataList = this.dataList.concat(res.data.list);
					pullScroll.endByPage(Math.ceil(res.data.count / 10), res.data.list);
				} else {
					this.$util.msg(res.resultNote);
				}
			}
		},
	}
</script>

<style lang="scss" scoped> 
	.content{
		padding: 20rpx;
		.list{
			.item{
				background: #FFFFFF;
				border-radius: 20rpx;
				padding: 30rpx;
				margin-bottom: 20rpx;
				.left{
					width: 40rpx;
					height: 40rpx;
					.image-block{
						width: 100%;
						height: 100%;
						display: block;
					}
				}
				.right{
					width: 88%;
					.name{
						font-size: 32rpx;
						font-family: PingFang SC;
						font-weight: bold;
						color: #333333;
					}
					.time{
						font-size: 24rpx;
						font-family: PingFang SC;
						font-weight: bold;
						color: #666666;
						margin-top: 10rpx;
					}
					.price{
						font-size: 26rpx;
						font-family: FZDaHei-B02S;
						font-weight: 400;
						color: #343434;
					}
				}
			}
		}
	}
	.foot{
		background: #FFFFFF;
		padding: 30rpx;
		position: fixed;
		bottom: 0;
		left: 0;
		z-index: 9999;
		width: 100%;
		box-sizing: border-box;
		.left{
			.icon{
				width: 40rpx;
				height: 40rpx;
				.image-block{
					width: 100%;
					height: 100%;
					display: block;
				}
			}
			.text{
				font-size: 26rpx;
				font-family: PingFang SC;
				font-weight: 500;
				color: #343434;
				margin-left: 30rpx;
			}
		}
		.right{
			width: 300rpx;
			height: 90rpx;
			background: $uni-color-bg;
			border-radius: 45rpx;
			font-size: 32rpx;
			font-family: PingFang SC;
			font-weight: bold;
			color: #fff;
			line-height: 90rpx;
			text-align: center;
		}
	}
</style>
